var app = getApp();
Page({
  data: {
    allSelect:"circle",
    num:0,
    count:0
  },

  deleteList(e) {
    const index = e.currentTarget.dataset.index;
    let list = this.data.list;
    list.splice(index, 1);
    this.setData({
      list: list
    });
    if (!list.length) {
      this.setData({
        hasList: false
      });

    } else {
      // this.getTotalPrice();
    }
  },


  onLoad: function (options) {
    var id = options.id;
    // 生命周期函数--监听页面加载 
    var list_ = this.data.list;
    var that = this;
    // for (let i = 0; i < list_.length; i++) {
    //   list_[i].show = false;
    // }
    wx.request({
      url: 'https://www.cakeyouxuan.com/small/my/favorites',
      data: {
        uid: id,
      },
      method: "POST",
      header: {
        "Content-Type": "application/x-www-form-urlencoded"  //post
      },
      success: function (res) {
        that.setData({
          list: res.data.list,
        });
        if (res.data.list == "") {
          wx.showToast({
            title: '收藏夹空空的',
            icon: 'loading',
            duration: 1000,
            success: function () {
              setTimeout(function () {
                wx.navigateBack(1);
              }, 1000) //延迟时间
            },
          })
        }
      },
    })
  }, 
  onChangeShowState: function (e) {
    var that = this;
    var list_ = this.data.list;
    var index_ = e.currentTarget.dataset.ind;
    if (list_[index_].show == true){
      for (let i = 0; i < list_.length; i++) {
        list_[i].show = false;
      }
    }else{
      for (let i = 0; i < list_.length; i++) {
        list_[i].show = false;
        list_[index_].show = true;
      }
    }
    
    console.log(index_)
    that.setData({
      list:list_
    })
  },

  //进入店铺
  rudian:function(e){
    var id = e.currentTarget.dataset.id;
    wx.switchTab({
      url: "/pages/yiguo/store/store",
    })
  },  

  //取消收藏
  quxiao:function(e){
    var id = e.currentTarget.dataset.id;
    var uid = app.whereId.uid;
    var that = this;
    wx.request({
      url: 'https://www.cakeyouxuan.com/small/my/favorites_del',
      data: {
        gid: id,
        uid: uid,
      },
      method: "POST",
      header: {
        "Content-Type": "application/x-www-form-urlencoded"  //post
      },
      success: function (res) {
        that.setData({
          list: res.data.list,
        });
        if (res.data.list == ""){
          wx.showToast({
            title: '收藏夹空空的',
            icon: 'loading',
            duration: 1000,
            success: function () {
              setTimeout(function () {
                wx.navigateBack(1);
              }, 1000) //延迟时间
            },
          }) 
        }
      },
    })
  },
})
